package com.nox.trademe.testapp.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.nox.trademe.testapp.R;
import com.nox.trademe.testapp.models.Item;

import java.util.ArrayList;
import java.util.List;

public class CustomItemListAdapter extends ArrayAdapter<Item> {

    private List<Item> itemsList;
    private Context context;

    public CustomItemListAdapter(ArrayList<Item> list, Context context) {
        super(context, R.layout.itemlisting_layout, list);
        this.itemsList = list;
        this.context = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View v = convertView;
        if (v == null) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = inflater.inflate(R.layout.itemlisting_layout, null);
        }

        Item category = itemsList.get(position);
        TextView text = (TextView) v.findViewById(R.id.itemlisting_name);
        text.setText(category.getName());
        notifyDataSetChanged();
        return v;
    }

}
